<?php

set_include_path('lib'.PATH_SEPARATOR.get_include_path());
require_once 'lib/Zend/Crypt/Hmac.php';
include('db_con.php');

function generateHmacKey($data, $apiKey=null){
	$hmackey = Zend_Crypt_Hmac::compute($apiKey, "sha1", $data);
	return $hmackey;
}

$txnid = "";
$txnrefno = "";
$txnstatus = "";
$txnmsg = "";
$firstName = "";
$lastName = "";
$email = "";
$street1 = "";
$city = "";
$state = "";
$country = "";
$pincode = "";
$mobileNo = "";
$signature = "";
$reqsignature = "";
$data = "";
$txnGateway = "";
$paymentMode = "";
$maskedCardNumber = "";
$cardType = "";
$customParamsName[0]= "";
$Comment = "";
$flag = "dataValid";

if(isset($_POST['TxId']))
{
	$txnid = $_POST['TxId'];
	$data .= $txnid;
}
if(isset($_POST['TxStatus']))
{
	$txnstatus = $_POST['TxStatus'];
	$data .= $txnstatus;
}
if(isset($_POST['amount']))
{
	$amount = $_POST['amount'];
	$data .= $amount;
}
if(isset($_POST['pgTxnNo']))
{
	$pgtxnno = $_POST['pgTxnNo'];
	$data .= $pgtxnno;
}
if(isset($_POST['issuerRefNo']))
{
	$issuerrefno = $_POST['issuerRefNo'];
	$data .= $issuerrefno;
}
if(isset($_POST['authIdCode']))
{
	$authidcode = $_POST['authIdCode'];
	$data .= $authidcode;
}
if(isset($_POST['firstName']))
{
	$firstName = $_POST['firstName'];
	$data .= $firstName;
}
if(isset($_POST['lastName']))
{
	$lastName = $_POST['lastName'];
	$data .= $lastName;
}
if(isset($_POST['pgRespCode']))
{
	$pgrespcode = $_POST['pgRespCode'];
	$data .= $pgrespcode;
}
if(isset($_POST['addressZip']))
{
	$pincode = $_POST['addressZip'];
	$data .= $pincode;
}
if(isset($_POST['signature']))
{
	$signature = $_POST['signature'];
}
/*signature data end*/

if(isset($_POST['TxRefNo']))
{
	$txnrefno = $_POST['TxRefNo'];
}
if(isset($_POST['TxMsg']))
{
	$txnmsg = $_POST['TxMsg'];
}
if(isset($_POST['email']))
{
	$email = $_POST['email'];
}

if(isset($_POST['customParamsName[0]']))
{
	$email = $_POST['customParamsName[0]'];
}


if(isset($_POST['addressStreet1']))
{
	$street1 = $_POST['addressStreet1'];
}
if(isset($_POST['addressStreet2']))
{
	$street2 = $_POST['addressStreet2'];
}
if(isset($_POST['addressCity']))
{
	$city = $_POST['addressCity'];
}
if(isset($_POST['addressState']))
{
	$state = $_POST['addressState'];
}
if(isset($_POST['addressCountry']))
{
	$country = $_POST['addressCountry'];
}

if(isset($_POST['mandatoryErrorMsg']))
{
	$mandatoryerrmsg = $_POST['mandatoryErrorMsg'];
}
if(isset($_POST['successTxn']))
{
	$successtxn = $_POST['successTxn'];
}
if(isset($_POST['mobileNo']))
{
	$mobileNo = $_POST['mobileNo'];
}
if(isset($_POST['txnGateway']))
{
	$txnGateway = $_POST['txnGateway'];
}
if(isset($_POST['paymentMode']))
{
	$paymentMode = $_POST['paymentMode'];
}
if(isset($_POST['maskedCardNumber']))
{
	$maskedCardNumber = $_POST['maskedCardNumber'];
}
if(isset($_POST['cardType']))
{
	$cardType = $_POST['cardType'];
}

if(isset($_POST['Comment']))
{
	$Comment = $_POST['Comment'];	
}

$respSignature = generateHmacKey($data,"d80c7103383242a914eec55e4f72017f371a03d5");

if($signature != "" && strcmp($signature, $respSignature) != 0)
{
	$flag = "dataTampered";
}
else
{
	// update database for transaction id
	$qUpd=mysql_query("update tblpayments set status=2, comments='$Comment',citrusTxnRefNo='$txnrefno',amount=$amount,txnstatus='$txnstatus',txnmessage='$txnmsg' where merchantTxnId='$txnid'");	
	
}



?>
<!DOCTYPE html>

<!--[if IE 7 ]><html class="ie ie7" lang="en"><![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"><![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"><!--<![endif]-->

<head>

<!-- Basic Page Needs

================================================== -->

<meta charset="utf-8">
<title>Shree Communications</title>
<link rel="icon" type="image/x-icon" href="shreelogo.ico">

<!-- Mobile Specific

================================================== -->

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<!-- CSS

================================================== -->

<link rel="stylesheet" href="../../css/style.css" />
<link rel="stylesheet" href="../../css/responsive.css" />

<!-- Java Script

================================================== -->

<script type="text/javascript" src="../../js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../../js/jquery-ui-1.8.24.custom.min.js"></script>
<script type="text/javascript" src="../../js/jquery.mobile.customized.min.js"></script>
<script type="text/javascript" src="../../js/jquery.easing.1.3.js"></script> 
<script type="text/javascript" src="../../js/camera.min.js"></script> 
<script type="text/javascript" src="../../js/jquery.isotope.min.js"></script>
<script type="text/javascript" src="../../js/jquery.flexslider-min.js"></script>
<script type="text/javascript" src="../../js/selectnav.min.js"></script>

<!--<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=AIzaSyB3tShW1hLlV2lYW8_sCVln6TLF2bWvgU8"></script>-->

<script type="text/javascript" src="../../js/jquery.googlemaps.1.01.min.js"></script>
<script type="text/javascript" src="../../js/theme.js"></script>

<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>

<body class="blog">
<div id="slider-wrap">
	<div class="camera_overlayer"></div>
</div>



<div id="wrapper">
	<div id="container">
		<!--start header -->
		<header id="header">
			<div id="logo">
				<a href="../../index.php"><strong>Shree</strong>  Communications</a>
			</div>	

			<div id="searchbox">
				<form action="#">
					<input type="text" id="search" placeholder="Search" />
					<button type="submit"></button>
				</form>
			</div>

			<div id="navigation">
				<ul id="nav">
					<li><a href="../../index.php">Home</a></li>							      
					<li><a href="../../contact.php">Contact</a></li>
                                         <li><a href="../../paynow2.php">Pay Now</a></li>
					<li  class="selected"><a href="../../FAQ.php">More +</a></li>
				</ul>
			</div>

		</header>

		<!--end header -->

		<div class="subheader">
			<div class="left">
				<span class="page-title">Payment</span>
				<span class="page-desc"><?php echo $txnstatus; ?></span>			</div>
		</div>

		<!--subheader -->

		<!--start content -->

		<div id="content">
		  <div class="module-box">
	<section role="banner">
  <!--payment method form start-->
  <?php 
					if($flag == "dataValid")
					{	
					?>
					<h3>Transaction Response</h3>
					<ul id="MerchantKitResponse" class="tbl-wrapper clearfix">
						<li class="tbl-header">
							<div class="tbl-col col-1">Txn Id</div>
							<div class="tbl-col col-2">Txn Ref No</div>
							<div class="tbl-col col-1">Email</div>
							<div class="tbl-col col-1">Txn Status</div>
							<div class="tbl-col col-1">Txn Message</div>
							<div class="tbl-col col-1">Amount</div>
							
						</li>
					<li>
							<div class="tbl-col col-1">
								<?php echo $txnid;?>
							</div>
							<div class="tbl-col col-2" style="height: auto;">
								<?php echo $txnrefno;?>
							</div>
							<div class="tbl-col col-1">
								<?php echo $email;?>
							</div>
							<div class="tbl-col col-1">
								<?php echo $txnstatus;?>
							</div>
							<div class="tbl-col col-1">
								<?php echo $txnmsg;?>
							</div>
							<div class="tbl-col col-1">
								<?php echo $amount;?>
							</div>
						</li>
					</ul>
					<h3>Consumer Details:</h3>
					<ul class="form-wrapper add-merchant clearfix">
						<li class="clearfix"><label>First Name: </label> <?php echo $firstName;?>
						</li>
						<li class="clearfix"><label>Last Name: </label> <?php echo $lastName;?>
						</li>
						<li class="clearfix"><label>Email: </label> <?php echo $email;?></li>
						<li class="clearfix"><label>Address: </label> <?php echo $street1;?>
						</li>
						<li class="clearfix"><label>City: </label> <?php echo $city;?></li>
						<li class="clearfix"><label>State: </label> <?php echo $state;?></li>
						<li class="clearfix"><label>Country: </label> <?php echo $country;?>
						</li>
						<li class="clearfix"><label>Zip Code: </label> <?php echo $pincode;?>
						</li>
						<li class="clearfix"><label>Mobile Number: </label> <?php echo $mobileNo;?>
						</li>
						<li class="clearfix"><label>Payment Mode: </label> <?php echo $paymentMode;?>
						</li>
						<li class="clearfix"><label>Transaction gateway: </label> <?php echo $txnGateway;?>
						</li>
						<li class="clearfix"><label>Masked Card Number: </label> <?php echo $maskedCardNumber;?>
						</li>
						<li class="clearfix"><label>Card Type: </label> <?php echo $cardType;?>
						</li>
						<li class="clearfix"><label>Comment: </label> <?php echo $Comment;?>
						</li>
						<?php 
						/* Suppose a Custom parameter by name Roll Number Comes in Post Parameter.
						 * then we need to retreive the RollNumber as
						 * $rollNumber = $_POST['Roll Number'];
						 * and the display the response value as shown in below HTML This code 
						 * can be added n times for n number of Custom Parameters*/
						?>
						<!-- <li class="clearfix"><label>Roll Number </label> <?php //echo $rollNumber;?>
						</li>  -->
					</ul>
					<?php 
					}
					else
					{
					?>
						<h3>Signature mismatch!!!</h3>
					<?php 	
					}
					?>
  <!--payment method form end-->
</section>
				<!--one half -->
				<!--one half -->
                <br class="clear" />
                <!--one-fourth --><!--one-fourth --><!--one-fourth -->
</div>

			<!--module-box -->

			

			<br class="clear" />	

		</div>

		<!--end content -->

	</div>

	<!--container -->


	<!--start footer -->
<?php include "../../footer.php"; ?>

	<!--end footer -->


	<!--subfooter -->

	

</div>

<!--wrapper -->

</body>

</html>